package com.qfedu.mesadmin.dev.count.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qfedu.mes.common.PageVO;
import com.qfedu.mes.entity.dev.DeviceLed;
import com.qfedu.mesadmin.dev.count.vo.DevTypeNameVO;
import com.qfedu.mesadmin.dev.count.vo.WorkShopVO;
import com.qfedu.mesadmin.dev.count.dao.DeviceLedDAO;
import com.qfedu.mesadmin.dev.count.params.SearchsParam;
import com.qfedu.mesadmin.dev.count.service.DeviceLedService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class DeviceLedServiceImpl implements DeviceLedService {
    @Resource
    private DeviceLedDAO deviceLedDAO;

    @Override
    public PageVO<DeviceLed> pageList(SearchsParam param) {
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        List<DeviceLed> deviceLeds = deviceLedDAO.selectInfo(param);
        Page pageInfo=(Page)deviceLeds;
        PageVO<DeviceLed> pageVO=new PageVO<>();
        pageVO.setTotal(pageInfo.getTotal());
        pageVO.setDataList(deviceLeds);
        return pageVO;
    }

    @Override
    public void addDevLed(DeviceLed deviceLed) {
        deviceLedDAO.insert(deviceLed);
    }

    @Override
    public String devCodes() {
        String t=String.valueOf(System.currentTimeMillis());
        t=t.substring(t.length()-4);
        return "M"+t;
    }

    @Override
    public List<WorkShopVO> workshopList() {
        List<WorkShopVO> workShopVOS = deviceLedDAO.selectWorkList();
        return workShopVOS;
    }

    @Override
    public void updateDevLed(DeviceLed deviceLed) {
        deviceLedDAO.update(deviceLed);
    }

    @Override
    public DeviceLed selectInfo(Integer id) {
        DeviceLed deviceLed = deviceLedDAO.selectById(id);
        return deviceLed;
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        deviceLedDAO.deleteBatch(ids);
    }

    @Override
    public List<DevTypeNameVO> devTypeNameList() {
        List<DevTypeNameVO> devTypeNameVOS = deviceLedDAO.selectDevTypeName();
        return devTypeNameVOS;
    }
}
